package com.squid.templateProject.controller;

import com.squid.templateProject.bean.Return;
import com.squid.templateProject.bean.req.PageReq;
import com.squid.templateProject.bean.req.organization.OrganizationInsertUpdateReq;
import com.squid.templateProject.bean.req.organization.OrganizationSelectPageReq;
import com.squid.templateProject.bean.resp.PageResp;
import com.squid.templateProject.bean.resp.organization.OrganizationSelectPageResp;
import com.squid.templateProject.service.organization.OrganizationEntityService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * Description
 *
 * @author jinhang
 * @since 2024-1-24
 **/
@RestController
@RequestMapping(value = "organization")
public class OrganizationController {
    @Resource
    OrganizationEntityService organizationEntityService;

    @PostMapping("insertOrganization")
    public Return<Object> insertOrganization(@RequestBody @Validated OrganizationInsertUpdateReq req) {
        organizationEntityService.insertOrganization(req);
        return Return.success();
    }

    @PostMapping("updateOrganization")
    public Return<Object> updateOrganization(@RequestBody @Validated OrganizationInsertUpdateReq req) {
        organizationEntityService.updateOrganization(req);
        return Return.success();
    }

    @PostMapping("deleteOrganization")
    public Return<Object> deleteOrganization(@RequestParam @NotBlank(message = "id不能为空") String id) {
        organizationEntityService.deleteOrganization(id);
        return Return.success();
    }

    @PostMapping("pageOrganization")
    public Return<PageResp<OrganizationSelectPageResp>> pageOrganization(@RequestBody @Validated PageReq<OrganizationSelectPageReq> req) {
        PageResp<OrganizationSelectPageResp> response = organizationEntityService.pageOrganization(req);
        return Return.<PageResp<OrganizationSelectPageResp>>success().data(response);
    }
}
